package com.fingard.dsp.bank.reqrespobj.qryrefund;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.qryrefund.detail.RetAtsRefundDetail;
import com.fingard.xml.XmlTextWriter;

public class RetAtsQryRefund extends RetAtsBase {
    public String reqSeqID = "";
    public String totleNum = "";
    public String totleAmount = "";

    public RetAtsQryRefund(ReqRespHeader p_header) {
        retHeader = p_header;
        reqSeqID = p_header.reqSeqID;
        retXmlWriter = new XmlTextWriter();
    }

    private int writeRdCount = 0;

    public int getWrittenRdCount() {
        return writeRdCount;
    }
    
    public boolean hasWrittenTotleNum = false;
    public boolean hasWrittenTotleAmount = false;
	public void writeTotalInfo() throws Exception {
		if(hasWrittenTotleNum) {
			throw new Exception("重复写入TotleNum");
		}
		if(hasWrittenTotleAmount) {
			throw new Exception("重复写入TotleAmount");
		}
		retXmlWriter.writeElementString("TotleNum", totleNum);
        retXmlWriter.writeElementString("TotleAmount", totleAmount);
        hasWrittenTotleNum = true;
        hasWrittenTotleAmount = true;
	}
	
	public void writeRetDetailOnly(RetAtsRefundDetail p_retDetail) throws Exception {
        writeRdCount++;
        if (writeRdCount == 1) {
            if (!hasWrittenRespCode) {
                writeRespCode("0");
            }
            if (!hasWrittenRespInfo) {
                writeRespInfo("");
            }
            retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        }
        retXmlWriter.writeStartElement("DetailRecord");
        p_retDetail.writeXE(retXmlWriter);
        retXmlWriter.writeEndElement();
    }
	
    public void writeRetDetail(RetAtsRefundDetail p_retDetail) throws Exception {
        writeRdCount++;
        if (writeRdCount == 1) {
            if (!hasWrittenRespCode) {
                writeRespCode("0");
            }
            if (!hasWrittenRespInfo) {
                writeRespInfo("");
            }
            retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        }

        retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
        retXmlWriter.writeElementString("TotleNum", totleNum);
        retXmlWriter.writeElementString("TotleAmount", totleAmount);

        retXmlWriter.writeStartElement("DetailRecord");
        p_retDetail.writeXE(retXmlWriter);
        retXmlWriter.writeEndElement();
    }
}
